/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action.user;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import po.Mail;
import po.News;
import po.User;
import service.UserService;

/**
 *
 * @author sony
 */
public class UserHomeAction extends ActionSupport {

    private UserService userService;
    private List<News> orgNews;
    private List<News> myNews;
    private List<Mail> mail;

    @Override
    public String execute() {

        if (ActionContext.getContext().getSession().get("user")==null) {
            return ERROR;
        } else {
        int userId = ((User) ActionContext.getContext().getSession().get("user")).getId();

        myNews = userService.getMyNews(userId).subList(0, Math.min(6, userService.getMyNews(userId).size()));
        orgNews = userService.getOrgNews(userId).subList(0, Math.min(6, userService.getOrgNews(userId).size()));
        mail = userService.getUnreadMails(userId).subList(0, Math.min(10, userService.getUnreadMails(userId).size()));
        return SUCCESS;
        }
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public List<News> getMyNews() {
        return myNews;
    }

    public void setMyNews(List<News> myNews) {
        this.myNews = myNews;
    }

    public List<News> getOrgNews() {
        return orgNews;
    }

    public void setOrgNews(List<News> orgNews) {
        this.orgNews = orgNews;
    }

    public List<Mail> getMail() {
        return mail;
    }

    public void setMail(List<Mail> mail) {
        this.mail = mail;
    }
}
